import React from 'react';
import Taro from '@tarojs/taro';
import './index.less';
import { NavBar } from '@nutui/nutui-react-taro'
import { Home, ArrowLeft } from '@nutui/icons-react-taro'

const CustomNavBar: React.FC<{ title: string }> = ({ title }) => {
  // 判断当前环境
  const isH5 = Taro.getEnv() === Taro.ENV_TYPE.WEB;
  // 返回上一页
  const handleGoBack = () => {
    Taro.navigateBack();
  };

  // 返回主页
  const handleGoHome = () => {
    Taro.switchTab({ url: '/pages/index/index' }); // 根据实际主页路径调整
  };
  return (
    isH5 && (
      <>
        <NavBar
          back={
            <>
              <ArrowLeft size={14} />
              返回
            </>
          }
          right={
            <span
              className="flex-center"
              onClick={handleGoHome}
            >
              <Home size={14} />
            </span>
          }
          onBackClick={handleGoBack}
        >
          <span>{title}</span>
        </NavBar>
      </>
    )
  );
};

export default CustomNavBar;
